根本不簡單,一大堆陷阱而且測值還沒跟你說
將0~9
A~Z
a~z
做成表格,去查表找位置(這樣可以避免遇到一些奇怪的測值像是+與空格)
base 就是從哪裡開始往上去找N
再找字元時,用到最大的就是從他開始(如果遇到A,就是從時開始,因為0~9進位弄不出A==>溢位)
N 進位數字即 ${a_0}*n^{n-1}+{a_1}*n^{n-2}.....{a_{n-1}}*n^{1}+a_n
$
是可以被$a_n*a_{n-1}*.....*a_{0}
$ 整除換句話說把其拆分相加==>再去被除==>也同樣是N base 的答案
+13A5
such number is impossible!
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
const string board = {"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"};
int main(int argc, char const *argv[])
{
string s;
while (getline(cin, s))
{
bool flag = 0;
int ans;
int base = 1, sum = 0;
for (int i = 0; i < s.length(); i++)
{
auto it = find(board.begin(), board.end(), s[i]);
if (it != board.end())
{
int side = distance(board.begin(), it);
// cout << side << endl;
if (base < side)
base = side;
sum = side + sum;
// cout << "base:" << base << endl;
}
}
// cout << sum << endl;
for (int i = base; i <= 62; i++)
{
if (sum % i == 0)
{
cout << i + 1 << endl;
break;
}
if (i == 62)
{
cout << "such number is impossible!" << endl;
break;
}
}
}
return 0;
}